package com.hundsun.cprs.yyt.service.order.dto;

import java.util.ArrayList;
import java.util.List;

import com.hundsun.cprs.yyt.common.enums.EnumAreaCode;
import com.hundsun.cprs.yyt.service.dilivery.domain.Delivery;
import com.hundsun.cprs.yyt.service.dilivery.domain.DiliveryAddress;
import com.hundsun.cprs.yyt.service.order.domain.Order;
import com.hundsun.cprs.yyt.service.order.domain.OrderItem;
import com.hundsun.cprs.yyt.service.order.enums.EnumsOrderStatus;
import com.hundsun.cprs.yyt.service.trade.domain.TradeMatchDetail;

public class OrderInfo extends Order {
    
    private List<OrderItem> orderItems;

    private Delivery delivery;//物流信息

    private List<TradeMatchDetail> tradeMatchDetailList;//交易对手方信息

    private DiliveryAddress diliveryAddress;//提货地址信息

    public List<OrderItem> getOrderItems() {
        return orderItems;
    }

    public void setOrderItems(List<OrderItem> orderItems) {
        this.orderItems = orderItems;
    }

    public Delivery getDelivery() {
        return delivery;
    }

    public void setDelivery(Delivery delivery) {
        this.delivery = delivery;
    }

    public List<TradeMatchDetail> getTradeMatchDetailList() {
        return tradeMatchDetailList;
    }

    public void setTradeMatchDetailList(List<TradeMatchDetail> tradeMatchDetailList) {
        this.tradeMatchDetailList = tradeMatchDetailList;
    }

    public boolean isWholesaleArea(){
        return EnumAreaCode.WHOLESALE_AREA.getCode().equalsIgnoreCase(getAreaCode());
    }
    
    public boolean isRetailArea(){
        return EnumAreaCode.RETAIL_AREA.getCode().equalsIgnoreCase(getAreaCode());
    }
    
    public boolean isEnturst(){
        return EnumsOrderStatus.ENTRUST.getStatus() == getStatus();
    }
    
    public void addOrderItem(OrderItem item){
        if (orderItems == null) {
            orderItems = new ArrayList<OrderItem>();
        }
        orderItems.add(item);
        //增加订单总商品数
        addQuantity(item.getQuantity());
        //增加订单价格
        addPrice(item.getQuantity() * item.getPrice());
        //增加订单配额
        addQuotaAmount(item.getQuantity() * item.getQuotaAmount());
        //增加订单赠送积分
        addQuotaRewardAmount(item.getQuotaRewardAmount());
        //增加订单赠送配额
        addIntegralRewardAmount(item.getIntegralRewardAmount());
    }
    
    protected void addQuantity(int quantity){
        Integer current = getQuantity() == null?0:getQuantity();
        setQuantity(current + quantity);
    }
    
    protected void addPrice(Long price){
        Long current = getPrice() == null?0l:getPrice();
        setPrice(current + price);
    }
    
    protected void addQuotaAmount(Long quotaAmount){
        Long current = getQuotaAmount() == null?0l:getQuotaAmount();
        setQuotaAmount(current + quotaAmount);
    }
    
    protected void addQuotaRewardAmount(Long quotaRewardAmount){
        Long current = getQuotaRewardAmount() == null?0l:getQuotaRewardAmount();
        setQuotaRewardAmount(current + quotaRewardAmount);
    }
    
    protected void addIntegralRewardAmount(Long integralRewardAmount){
        Long current = getIntegralRewardAmount() == null?0l:getIntegralRewardAmount();
        setIntegralRewardAmount(current + integralRewardAmount);
    }

    public DiliveryAddress getDiliveryAddress() {
        return diliveryAddress;
    }

    public void setDiliveryAddress(DiliveryAddress diliveryAddress) {
        this.diliveryAddress = diliveryAddress;
    }
}
